package com.leozhang.portalssm.controller;


import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.leozhang.portalssm.entity.Assets;
import com.leozhang.portalssm.entity.AssetsExample;
import com.leozhang.portalssm.entity.AssetsStatus;
import com.leozhang.portalssm.mapper.AssetsMapper;
import com.leozhang.portalssm.mapper.AssetsStatusMapper;
import com.leozhang.portalssm.service.AssetService;
import com.leozhang.portalssm.service.AssetsStatusService;
import com.leozhang.portalssm.util.ChangeChar;
import com.leozhang.portalssm.util.Result;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

//访问url路径的映射
@RequestMapping("/assets-status")
//声明该类是一个mvc结构的控制器
@Controller
public class AssetsStatusController {



        @Autowired
        private AssetsStatusService assetsStatusService;

        //代表当访问/assettype/list的时候执行该函数
        @RequiresPermissions("permission:query")
        @RequestMapping("/list")
        public String assetsList(){

        //type/sex/list表示当前函数最后返回webapp->WEB-INF->views->type->sex->list.jsp页面
        return "type/assets/list";
    }

        @RequestMapping("/list/page")
        @ResponseBody
        public Result sexListPage(@RequestParam(value = "pno",defaultValue = "1")int pno,
        @RequestParam(value = "psize",defaultValue ="10")int psize,
        @RequestParam(value="assetStatusName",defaultValue = "")String assetStatusName,
        @RequestParam(value="sortField",defaultValue = "")String sortField,
        @RequestParam(value="sortType",defaultValue = "")String sortType)
        {
            return assetsStatusService.getListForPage(pno,psize,assetStatusName,sortField,sortType);
        }

    //跳转至添加页面
    @RequestMapping("/add/page")
    public String toaddpage(){
        return "type/assets/add";
    }

    @RequestMapping("/add")
    public String addAssetsstatus(AssetsStatus assetsStatus){
        assetsStatusService.insertAssets(assetsStatus);
        return "redirect:/assets-status/list";
    }


    @RequestMapping("/edit/page")
    public String editPage(Long id, Model model){

        System.out.println("zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"+id);
        AssetsStatus assetsStatus=assetsStatusService.selectAssetsById(id);
        //这里的key命名为formData是为了写别的模块可以快速的改
        model.addAttribute("formData",assetsStatus);
        return "type/assets/edit";
    }
    @RequestMapping("/edit")
    public String updateAssetstatus(AssetsStatus assetsStatus){
        assetsStatusService.updateAssetsstatus(assetsStatus);
        return "redirect:/assets-status/list";
    }
    @RequestMapping("/delete")
    public String assetsDelete(Long id){

        System.out.println("----------------------------------"+id);
        assetsStatusService.deleteAssetsStatusById(id);
        return "redirect:/assets-status/list";
    }





    }


